from data_visualization.html_data_visualization import HtmlDataVisualization


class ComboChart(HtmlDataVisualization):
    chart_title = ""
    
    xAxis_name = ""
    xAxis_data = []
    
    yAxis_name_1 = ""
    yAxis_data_1 = []
    
    yAxis_name_2 = ""
    yAxis_data_2 = []
    
    chart_type_1 = ""
    chart_type_2 = ""
    
    use_2nd_axis = True
    
    def __init__(self):
        HtmlDataVisualization.__init__(self)
        self.algorithm_name = "复合图表"
        self.html_template_name = "combo_chart_1-template.html"
        
    def setXAxisAndYAxisName(self, xAxis_name, yAxis_name_1, yAxis_name_2):
        self.xAxis_name = xAxis_name
        self.yAxis_name_1 = yAxis_name_1
        self.yAxis_name_2 = yAxis_name_2
        
        self.xAxis_data = self.data_source[self.xAxis_name].values.tolist()
        self.yAxis_data_1 = self.data_source[self.yAxis_name_1].values.tolist()
        self.yAxis_data_2 = self.data_source[self.yAxis_name_2].values.tolist()
    
    def prepareHtmlItems(self):
        HtmlDataVisualization.prepareHtmlItems(self)
        if self.use_2nd_axis:
            self.html_template_name = "combo_chart_2-template.html"
        self.html_items["#chart_title#"] = self.chart_title
        self.html_items["#xAxis_name#"] = self.xAxis_name
        self.html_items["#xAxis_data#"] = self.xAxis_data
        self.html_items["#yAxis_name_1#"] = self.yAxis_name_1
        self.html_items["#yAxis_data_1#"] = self.yAxis_data_1
        self.html_items["#yAxis_name_2#"] = self.yAxis_name_2
        self.html_items["#yAxis_data_2#"] = self.yAxis_data_2
        self.html_items["#chart_type_1#"] = self.chart_type_1
        self.html_items["#chart_type_2#"] = self.chart_type_2
